﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Xml;

namespace LevelEditor.Document
{
    [Serializable]
    public class Layer
    {
        #region Properties

        /// <summary>
        /// Size of this layer in number of tiles
        /// </summary>
        public Size Size { get; set; }

        /// <summary>
        /// True = layer is drawn
        /// </summary>
        public bool Visible { get; set; }

        /// <summary>
        /// True = use the collision data of this layer
        /// </summary>
        public bool Collision { get; set; }

        /// <summary>
        /// True = layer repeats on the x-axis
        /// </summary>
        public bool HorizontalRepeat { get; set; }

        /// <summary>
        /// True = layer repeats on the y-axis
        /// </summary>
        public bool VerticalRepeat { get; set; }

        /// <summary>
        /// True = layer is scrolled automatically on the x-axis 
        /// based on position of player relative to player's 
        /// starting layer
        /// </summary>
        public bool HorizontalParallax { get; set; }

        /// <summary>
        /// True = layer is scrolled automatically on the y-axis 
        /// based on position of player relative to player's 
        /// starting layer
        /// </summary>
        public bool VerticalParallax { get; set; }

        /// <summary>
        /// Automatically scroll this layer by this amount per second
        /// </summary>
        public Point AutoScroll { get; set; }

        /// <summary>
        /// Size of a tile in pixels
        /// </summary>
        public Size TileSize { get; set; }

        /// <summary>
        /// List of tile sets to use for this layer
        /// </summary>
        public List<TileSet> TileSets { get; set; }

        /// <summary>
        /// List of tiles in this layer
        /// </summary>
        public XmlSerializableDictionary<Point, Tile> Tiles { get; set; }

        #endregion

        #region Constructors

        public Layer()
        {
            Size = new Size(40, 20);
            Visible = true;
            TileSets = new List<TileSet>();
            Tiles = new XmlSerializableDictionary<Point, Tile>();
            TileSize = new Size(40, 40);
        }

        public Layer(Size size, Size tileSize)
        {
            Size = size;
            Visible = true;
            TileSets = new List<TileSet>();
            Tiles = new XmlSerializableDictionary<Point, Tile>();
            TileSize = tileSize;
        }

        public Layer(Layer copy)
        {
            Size = copy.Size;
            Visible = copy.Visible;
            TileSets = new List<TileSet>(copy.TileSets);
            Tiles = new XmlSerializableDictionary<Point, Tile>(copy.Tiles);
            TileSize = copy.TileSize;
            HorizontalRepeat = copy.HorizontalRepeat;
            HorizontalParallax = copy.HorizontalParallax;
            VerticalParallax = copy.VerticalParallax;
            VerticalRepeat = copy.VerticalRepeat;
            AutoScroll = copy.AutoScroll;
        }

        #endregion

    }
}
